package cc.sunni.sleeve.api.v1;

import cc.sunni.sleeve.core.interceptors.ScopeLevel;
import cc.sunni.sleeve.exception.http.NotFoundException;
import cc.sunni.sleeve.model.Banner;
import cc.sunni.sleeve.service.BannerService;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;

/**
 * @author jl
 * @since 2021/8/5 22:06
 */
@RestController
@RequestMapping("/banner")
@RequiredArgsConstructor
public class BannerController {
    private final BannerService bannerService;

    @GetMapping("/name/{name}")
    public Banner getByName(@PathVariable @NotBlank String name) {
        Banner banner = bannerService.getByName(name);
        if(banner == null){
            throw new NotFoundException(30005);
        }
        return banner;
    }

}
